<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0,maximum-scale=1.0" />
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css"/>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__PUBLIC__/js/public.js" type="text/javascript" charset="utf-8"></script>
    <title>我的订单</title>
</head>
<body>
<div id="order">
    <div class="orderBar">
        <a href="javascript:void(0);" id="allBar" class="on">全部订单</a>
        <a href="javascript:void(0);" id="stayBar">待支付</a>
        <a href="javascript:void(0);" id="hasBar">待评价</a>
    </div>
    <div class="orderCon">

    </div>
    <div class="orderCon" style="display:none">


    </div>

    <div class="orderCon" style="display:none">



    </div>

</div>
<script type="text/javascript">
    $(function(){
        //tab头
        var tabHeader = $('.orderBar').find('a');
        //index :0全部，1待评价，2已评价
        var getOrderList = function(index){
            var orderCon = $('.orderCon').eq(index);
            orderCon.fadeIn().siblings('.orderCon').hide();
            var is_comment = '';
            if(index==0){
                is_comment='';
            }else if(index==1){
                is_comment=1;
            }else if(index==2){
                is_comment=2;
            }

            $.ajax({
                url:url()+'index.php?s=/Home/Order/getOrderList',
                dataType:'json',
                data:{
                    is_comment:is_comment
                },
                success:function(data){
                    if(data.state==1){
                        orderCon.empty();
                        var list = data.data;
                        console.log(list.length);
                        var len = list.length;
                        if(!list||len==0){
                            return;
                        }
                        var html='';
                        for(var i = 0;i<len;i++){
                            var isShowPay = "none";
                            var isShowComment = "none";
                            var isShowAngin = "none";
                            if(list[i].is_comment=='1'&&list[i].order_state=='2'){
                                isShowComment  ="block";
                            }
                            if(list[i].is_comment=='2'&&list[i].order_state=='2'){
                                isShowAngin  ="block";
                            }
                            if(list[i].order_state=='1'){
                                isShowPay  ="block";
                            }
                            html += '<div class="goodsList">'
                                +'<img class="goodsIcon" src="'+'__PUBLIC__/'+list[i].image+'"/>'
                                +'<div class="goodsCon">'
                                +' <a href="javascript:void(0);" class="goodsName">'+list[i].dish_name+list[i].allcont+'等件商品</a>'
                                +'<span class="goodsType">订单已完成</span>'
                                +'<div class="discount">评价可得优惠券最高可得10元优惠</div>'
                                +'<span class="goodsTime">'+list[i].createtime+'</span>'
                                +'<span class="goodsPrice">￥<i class="price">'+list[i].order_price+'</i></span>'
                                +'</div>'
                                +'<div class="goodsState">'
                                +'<a href="javascript:void(0);" class="buy" style="float: right;display: '+isShowPay+';">立即支付</a>'
                                +' <a href="javascript:void(0);" class="recur" style="float: right;display: '+isShowAngin+';">再来一单</a>'
                                +'<a href="javascript:void(0);" class="noweval" style="float: right;display: '+isShowComment+';">立即评价</a>'
                                +'</div>'
                                +'</div>';

                        }
                        orderCon.html(html);
                    }

                },
                error:function(e){
                    alert('获取数据失败');
                }
            });

        }
        tabHeader.click(function(){
            var index = $('.orderBar').find('a').index(this);
            $(this).addClass('on').siblings('a').removeClass('on');
            getOrderList(index);
        });


        getOrderList(0);


    });
</script>

</body>
</html>
